<?php
/*
* File：管理用户
* Author：易如意
* QQ：51154393
* Url：www.eruyi.cn
*/

require_once 'globals.php';
include_once 'header.php';

 $sql="select * from eruyi_user where 1";
 $queryc=$db->query($sql);
 $nums=$db->num_rows($queryc);
 $enums=30;  //每页显示的条目数 
 $page=isset($_GET['page']) ? intval($_GET['page']) : 1;
 $av_url = $_SERVER['SERVER_NAME'].dirname($_SERVER["REQUEST_URI"]);
 $url="adm_user.php?page=";
 $bnums=($page-1)*$enums;
 
 $ids = isset($_POST['ids']) ? $_POST['ids'] : '';
 if($ids){
	$idss = '';
	foreach ($ids as $value) {
		$idss .= $value.",";
	}
	$idss = rtrim($idss, ",");
	$sql="DELETE FROM `eruyi_user` WHERE `uid` in ($idss)";
	$query=$db->query($sql);
	if($query){
		echo "<script>alert('删除成功');</script>";
	}
 }
?>
<form action="adm_user.php" method="post" name="suer" id="suer">
<label for="user" />查找用户</label>
<input type="text" name="user" /><input type="submit" value="查找" />
</form>
<form action="" method="post" name="form_log" id="form_log">
  <table width="100%" id="adm_log_list" class="item_list">
  <thead>
      <tr>
		<th><input type="checkbox" onclick="checkAll();" class="ids" id="all"/></th>
		<th><b>头像</b></th>
        <th><b>ID</b></th>
		<th><b>用户名</b></th>
		<th><b>账号</b></th>
		<th><b>用户组</b></th>
		<th><b>会员到期时间</b></th>
		<th><b>我邀请的</b></th>
		<th><b>邀请人</b></th>
		<th><b>注册时间</b></th>
		<th><b>注册IP</b></th>
		<th><b>机器码</b></th>
		<th><b>状态</b></th>
        <th><b>管理</b></th>
      </tr>
	</thead>
 	<tbody>
<?php
 $user = isset($_POST['user']) ? addslashes(trim($_POST['user'])) : '';
 if($user != ''){
 $sql="select * from eruyi_user where user='$user' order by uid desc limit $bnums,$enums";
 }else{
 $sql="select * from eruyi_user where 1 order by uid desc limit $bnums,$enums";
 }
 $query=$db->query($sql);
 while($rows=$db->fetch_array($query)){
?>
      <tr>
      <td><input type="checkbox" name="ids[]" value="<?php echo $rows['uid']; ?>" class="ids" /></td>
	  <td><?php if(strpos($rows['pic'],"http")!==false): ?><img src="<?php echo $rows['pic']?>" class="avatar"/><?php elseif($rows['pic']==''): ?><img src="<?php echo 'http://'.dirname($av_url).'/pic/0.png'?>" class="avatar"/><?php else: ?><img src="<?php echo 'http://'.dirname($av_url).$rows['pic']?>"  class="avatar"/><?php endif; ?></td>
	  <td><?php echo $rows['uid']; ?></td>
	  <td><?php echo $rows['name']; ?></td>
      <td><?php echo $rows['user']; ?></td>
      <td><?php if($rows['vip']>time() || $rows['vip']=='999999999'): ?><font color=red>会员用户</font><?php else: ?>普通用户<?php endif; ?></td>
	  <td><?php if($rows['vip']=='999999999'){
		echo '永久会员'; 
	  }else{
		if($rows['vip']>time()) echo gmdate("Y-m-d H:i:s",$rows['vip']+8*3600);
	  }
	  ?></td>
	  <td><?php echo '已邀请：' . $rows['i_inv'].'人'; ?></td>
	  <td><?php if($rows['inv']==0){
		echo '无邀请人'; 
	  }else{
		echo '邀请人ID：'.$rows['inv']; 
	  }
	  ?></td>
	  <td><?php echo gmdate("Y-m-d H:i:s",$rows['regdate']+8*3600); ?></td>
	  <td><?php echo $rows['regip']; ?></td>
	  <td><?php echo $rows['markcode']; ?></td>
	  <td><?php if($rows['lock']=='y'):?><font color=red>禁用<?php else: ?><font color=green>正常<?php endif; ?></font></td>
	  <td><a href="edit_user.php?uid=<?php echo $rows['uid']; ?>" target="_self">编辑</a></td>
      </tr>
<?php
 }
?>
	</tbody>
	</table>
	<div class="list_footer">
	选中项：<a href="javascript:void(0);" onclick="delsubmit()" class="care">删除</a>
	</div>
</form>
<?php if($user == ''): ?>
<div class="page"><?php echo pagination($nums,$enums,$page,$url); ?></div>
<?php endif; ?>
<script>
function checkAll() {
    var code_Values = document.getElementsByTagName("input");
	var all = document.getElementById("all");
    if (code_Values.length) {
        for (i = 0; i < code_Values.length; i++) {
            if (code_Values[i].type == "checkbox") {
                code_Values[i].checked = all.checked;
            }
        }
    } else {
        if (code_Values.type == "checkbox") {
            code_Values.checked = all.checked;
        }
    }
}
function delsubmit(){
	var delform = document.getElementById("form_log");
	delform.submit();
}
var div = document.getElementById('adm_user'); 
div.setAttribute("class", "show"); 
</script>
<?php 
include_once 'footer.php';
?>